package strangeattractor.UI;

import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import strangeattractor.core.Transformer;
import strangeattractor.equations.Lorenz;
import strangeattractor.equations.Lorenz84;

public class Lorenz84Modifier extends EquationModifier {

	private Lorenz84 equation;
	private JSlider sliderA;
	private JSlider sliderB;
	private JSlider sliderC;
	private JSlider sliderD;
	private JSlider sliderE;
	
	public Lorenz84Modifier() {
		super();
		this.center.gen.zoom(30);
	}
	
	@Override
	protected void fill(JPanel equationModifierPanel) {
		initializeA(equationModifierPanel);
		initializeB(equationModifierPanel);
		initializeC(equationModifierPanel);
		initializeD(equationModifierPanel);
		initializeE(equationModifierPanel);
	}
	
	private void initializeE(JPanel equationModifierPanel) {
		this.sliderE = new JSlider(0, 5000);
		sliderE.setOrientation(SwingConstants.VERTICAL);
		equationModifierPanel.add(sliderE);
		sliderE.setValue(0);
		sliderE.addChangeListener(new ChangeListener(){

			@Override
			public void stateChanged(ChangeEvent arg0) {
				equation.E = (((double)sliderE.getValue())/10000);
				center.preview(center.getSize());
			}
			
		});
	}

	private void initializeD(JPanel equationModifierPanel) {
		this.sliderD = new JSlider(0, 10000);
		sliderD.setOrientation(SwingConstants.VERTICAL);
		equationModifierPanel.add(sliderD);
		sliderD.setValue(0);
		sliderD.addChangeListener(new ChangeListener(){

			@Override
			public void stateChanged(ChangeEvent arg0) {
				equation.D = (((double)sliderD.getValue())/1000);
				center.preview(center.getSize());
			}
			
		});
	}


	private void initializeC(JPanel equationModifierPanel) {
		this.sliderC = new JSlider(0, 10000);
		sliderC.setOrientation(SwingConstants.VERTICAL);
		equationModifierPanel.add(sliderC);
		sliderC.setValue(0);
		sliderC.addChangeListener(new ChangeListener(){

			@Override
			public void stateChanged(ChangeEvent arg0) {
				equation.C = (((double)sliderC.getValue())/100);
				center.preview(center.getSize());
			}
			
		});
	}


	private void initializeB(JPanel equationModifierPanel) {
		this.sliderB = new JSlider(0, 10000);
		sliderB.setOrientation(SwingConstants.VERTICAL);
		equationModifierPanel.add(sliderB);
		sliderB.setValue(0);
		sliderB.addChangeListener(new ChangeListener(){

			@Override
			public void stateChanged(ChangeEvent arg0) {
				equation.B = (((double)sliderB.getValue())/1000);
				center.preview(center.getSize());
			}
			
		});
	}


	private void initializeA(JPanel equationModifierPanel){
		this.sliderA = new JSlider(0, 10000);
		sliderA.setOrientation(SwingConstants.VERTICAL);
		equationModifierPanel.add(sliderA);
		sliderA.setValue(0);
		sliderA.addChangeListener(new ChangeListener(){

			@Override
			public void stateChanged(ChangeEvent arg0) {
				try {
				equation.A = (((double)sliderA.getValue())/1000);
				center.preview(center.getSize());
				}
				catch (Throwable t) {
					t.printStackTrace();
				}
			}
			
		});
	}


	@Override
	protected Transformer initializeEquation() {
		this.equation = new Lorenz84(0, 0, 0, 0, 0);
		return equation;
	}

}
